package com.rdk.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.rdk.constant.CodeConstant;
import com.rdk.constant.Forward;
import com.rdk.constant.StrConstant;
import com.rdk.entity.TShare;
import com.rdk.entity.TShareAttachment;
import com.rdk.service.TShareAttachmentService;
import com.rdk.service.TShareService;
import com.rdk.utils.CommonUtil;
import com.rdk.utils.TimeUtil;

/**
 * 关注app
 * @author wang_lei
 *
 */
@Controller
public class Attention extends BaseAction {
	
	@Autowired
	private TShareService shareService;
	
	@Autowired
	private TShareAttachmentService attaService;
	
	/**
	 * to首页
	 * @param request
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "attention/index")
	public String toAttentionIndex(HttpServletRequest request, ModelMap map){
		
		request.getParameter("clienKey");
	
		return Forward.ActionPage.ATTENTION_INDEX;
	}
	
	/**
	 * 获取分享图片()
	 * @param request
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "getSharePhoto")
	public ModelAndView getSharePhoto(HttpServletRequest request, ModelMap map){
		
		//String userId = CommonUtil.getSession(request, StrConstant.USERID); 
		String userId = "4328621732";
		Map<String, Object> shareMap = new HashMap<String,Object>();
		shareMap.put("userId", userId);
		
		/*List<TShare> shareList = shareService.selectByUserId(shareMap);
		List<TShareAttachment> list = new ArrayList<>();
		int index = 0;
		for (TShare tShare : shareList) {
			if(index >= 4)
				break;
			List<TShareAttachment> attachments = attaService.selectByShareId(tShare.getShareId());
			if(attachments.size()>0){
				for (TShareAttachment tShareAttachment : attachments) {
					list.add(tShareAttachment);
				}
			}
			
			index += attachments.size();
			System.out.println(attachments.size());
		}*/
		List<TShareAttachment> list = attaService.selectByShareId(userId);
		return new ModelAndView("jsonView", "rCode", list);
	}

}
